package org;



import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import vo.Custom;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.xml.internal.txw2.TXW;

public class ChangePassword extends ActionSupport {
	private String oldPassword;
	private String password;

	@Override
	public String execute() throws Exception {
		Custom custom = (Custom) ActionContext.getContext().getSession().get("custom");
		System.out.println(custom.getPassword());
		System.out.println(oldPassword);
		if (oldPassword.equals(custom.getPassword())) {
			SessionFactory sf = new Configuration().configure()
					.buildSessionFactory();
			Session session = sf.openSession();
			Transaction tx =session.beginTransaction();
			custom.setPassword(password);
			session.saveOrUpdate(custom);
			tx.commit();
			session.close();
			
			
			return SUCCESS;
		} else
			return ERROR;

	}



	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

}
